package com.enzoism.springboot.dive.config;

import lombok.SneakyThrows;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.cache.jcache.JCacheCacheManager;
import javax.cache.CacheManager;
import javax.cache.Caching;

@Configuration
@EnableCaching
public class CacheConfig {

    @SneakyThrows
    @Bean
    public JCacheCacheManager cacheManager() {
        CacheManager jCacheManager = Caching.getCachingProvider().getCacheManager(
                getClass().getResource("/ehcache.xml").toURI(),
                getClass().getClassLoader()
        );
        return new JCacheCacheManager(jCacheManager);
    }
}